// 登录
$(".my_submit_btn").click(function () {
    $tel =  $('.tel').val();
    $password =  $('.pwd').val();
//        var reg = /^(\+?44|0)7\d{9}$/;
    if ($tel){
        if (!checkTel($tel)) return false;
    }
    if ('' == $tel){
        layer.msg('请输入正确的手机号',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else if ('' == $password){
        layer.msg('密码不能为空',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else{
        $.ajax({
            type: "post",
            url: "/userweb/login/login",
            cache: false,
            data: {account: $tel, password: $password, type:'WEB'},
            dataType: "json",
            success: function (data) {
                if (200 == data.status) {
                    localStorage.user_id    = data.data.id;
                    localStorage.user_name  = data.data.name;
                    localStorage.user_image = oss_url + data.data.image;
                    localStorage.web_token  = data.web_token;
                    localStorage.city       = data.data.city;
                    var str         = location.href; //取得整个地址栏
                    var productId   = getUrlParam(str,'productId');
                    if (productId){
                        location.href = "/userweb/index/productInfo.html?productId="+productId;
                    }else if(data.data.is_complete == 0) {
                        location.href = "/userweb/index/improveInfo.html";
                    }else{
                        location.href = "/userweb/index/index.html";
                    }
                }else {
                    layer.msg('手机号或密码错误',{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }
        });
    }
});

/**
 * 从地址栏获取参数.
 * @param url
 * @param name
 * @returns {*}
 */
function getUrlParam(url,name) {
    var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
    var matcher = pattern.exec(url);
    var items = null;
    if(null != matcher){
        try{
            items = decodeURIComponent(decodeURIComponent(matcher[1]));
        }catch(e){
            try{
                items = decodeURIComponent(matcher[1]);
            }catch(e){
                items = matcher[1];
            }
        }
    }
    return items;
}